<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class msearch extends MY_Model {

    var $theme_data = array(
        'layout_main' => 'layout',
        'left' => 'include/leftcp',
    );
    public $mytable = "search";
    public $primaryKey = "search_id";
    public $resCode = "SEARCH";

    function __construct() {
        parent::__construct();
    }

    function field() {
		$fieldData = array();
		$fieldData['search_code'] = '';
		$fieldData['search_keyword'] = '';
		$fieldData['search_time_create'] = time();
		$fieldData['search_time_update'] = time();
		$fieldData['search_cache'] = '';
		$fieldData['search_count'] = 1;
		return $fieldData;
    }
	
	function update_view($search_id = 0){
		//update view
        $this->db->where("search_id", $search_id);
        $this->db->set('search_count', 'search_count+1', false);
        $this->db->set('search_time_update', time(), false);
        $this->db->update($this->mytable, array());
	}
	
	function pagination_json($data, $config = array()){
		$result = array();
		if (isset($config['cur_page']) && isset($config['per_page'])){
			$from = ($config['cur_page'] - 1) * $config['per_page'];
			$to = $config['cur_page'] * $config['per_page'];
			for($i=$from; $i<$to; $i++){
				if(isset($data[$i]))
					$result[] = $data[$i];
			}
		
		}
		return $result;
		
	}
}

?>